<template>
  <div>
    <el-table
      :data="roleList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="角色编号"></el-table-column>
      <el-table-column prop="rolename" label="角色名称"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="danger" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" plain @click="edit(scope.row.id)"
            >编辑</el-button
          >
          <!-- <el-button type="primary" @click="del(scope.row.id)">删除</el-button> -->
          <v-del @del="del(scope.row.id)"></v-del>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { roleDel } from "../../../request/api";
import { successAlert, warningAlert } from "../../../util/alert";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      roleList: "role/list",
    }),
  },
  methods: {
    ...mapActions({
      reqRoleList: "role/reqChangeList",
    }),
    //删除
    del(id) {
      //删除具体的项
      roleDel({ id: id }).then((res) => {
        if (res.data.code == 200) {
          //成功的弹窗
          successAlert(res.data.msg);
          //重新请求列表数据
          this.reqRoleList();
        } else {
          //失败的弹窗
          warningAlert(res.data.msg);
        }
      });
    },
    edit(id) {
      this.$emit("edit", id);
    },
  },
  mounted() {
    this.reqRoleList();
  },
};
</script>
<style scoped>
</style>